package com.hz.house.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.hz.house.bean.vo.AnswerQuestionInfo;
import com.hz.house.bean.vo.AnswerReplyInfo;
import com.hz.house.bean.vo.FAQInfo;
import com.hz.house.bean.vo.FAQSearch;
import com.hz.house.service.BuyHouseFAQService;
import com.hz.house.token.CurrentUser;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 	买房问答板块的接口
 * @author lfw
 */
@Api(value = "买房问答接口")
@RequestMapping("/api/v2/bhfqa")
@RestController
public class BuyHouseFAQController {
	
	@Autowired
	private BuyHouseFAQService buyHouseFAQService;
	
	
	@ApiOperation(value = "提问")
	@PostMapping("/askFaq")
	public Object askQuestionFaq(@RequestBody FAQInfo faq) {
		return buyHouseFAQService.askQuestionFaq(faq, CurrentUser.getCurrentUserId());
	}
	
	@ApiOperation(value = "获取问答列表:order=1按照浏览量排序，=2按照时间降序排序。"
			+ "isAnswer 0未解答，1已回答，2全部.type用,号分隔。不搜索的时候，全部不传,或则和传null")
	@PostMapping("/getFqaList")
	public Object getFaqList(@RequestBody FAQSearch search) {
		return this.buyHouseFAQService.getFaqList(search);
	}
	
	@ApiOperation(value = "回答问题")
	@PostMapping("/anserQ")
	public Object answerQuestion(@RequestBody AnswerQuestionInfo aqi) {
		return this.buyHouseFAQService.answerQuestion(aqi,CurrentUser.getCurrentUserId());
	}
	
	@ApiOperation(value = "点赞回答：iHasPraise=true,取消点赞，iHasPraise=false，执行点赞")
	@GetMapping("/praiseA")
	public Object praiseAnswer(Integer answerId,Integer iHasPraise) {
		return this.buyHouseFAQService.praiseAnswer(answerId, CurrentUser.getCurrentUserId(),iHasPraise);
	}
	
	
	@ApiOperation(value = "回复回答")
	@PostMapping("/replyA")
	public Object replyAnswer(@RequestBody AnswerReplyInfo reply) {
		return this.buyHouseFAQService.replyAnswer(reply, CurrentUser.getCurrentUserId());
	}
	
	@ApiOperation(value = "获取问答的详情")
	@GetMapping("/getFaqDetail")
	public Object getFaqDetail(Integer faqId) {
		return this.buyHouseFAQService.getFaqDetail(faqId, CurrentUser.getCurrentUserId());
	}
	
	@ApiOperation(value = "追问")
	@GetMapping("/zhuiwen")
	public Object zhuiWen(String content,Integer faqId) {
		return this.buyHouseFAQService.zhuiWen(content, faqId);
	}

	@ApiOperation(value = "获取回答和回复列表")
	@GetMapping("/faqAnswers")
	public Object getAswersAndReplysList(Integer page,Integer faqId) {
		return this.buyHouseFAQService.getAswersAndReplysList(page,CurrentUser.getCurrentUserId(),faqId);
	}
	
	@ApiOperation(value = "我的问答-查询我的提问")
	@GetMapping("/getMyQuestion")
	public Object getMyQestion(Integer page) {
		return this.buyHouseFAQService.getMyQestion(page,CurrentUser.getCurrentUserId());
	}
	
	@ApiOperation(value ="我的问答-我的回答")
	@GetMapping("/getMyAnswer")
	public Object getMyAnswers(Integer page) {
		return this.buyHouseFAQService.getMyAnswers(page,CurrentUser.getCurrentUserId());
	}
	
	@ApiOperation(value = "生成买房问答的海报")
	@GetMapping("/getFAQBill")
	public Object generateFAQBill(Integer faqId){
		return this.buyHouseFAQService.generateFAQBill(faqId);
	}
	
}
